const express = require("express");
const ejs = require('ejs');
const path = require('path');
const app = express();
const ___dirname = path.resolve(__dirname, ".");
const request = require('request');

app.use("/static", express.static('public'));

app.engine('.html', ejs.renderFile); //设置模板渲染
app.set('view engine', 'html');
app.set("views", path.resolve(__dirname, "./views"))
app.get('/', function (req, res) {
  res.render('index')
})
app.get('/on', function (req, res) {
  console.log(req.query)
  const token = "a700123";
  const event=req.query.event,
        eventState=req.query.eventState;
  const url = "http://192.168.0.100/?token="+token+"&event="+event+"&eventState="+eventState+""
  request(url, function (error, response, body) {
    res.send(body)
  });
})
app.get('/state', function (req, res) {
  console.log(req.query)
  const token = "a700123";
  const event=req.query.event,
        eventState=req.query.eventState;
  const url = "http://192.168.0.100/?token="+token+"&event="+event+"&eventState="+eventState+""
  request(url, function (error, response, body) {
    res.send(body)
  });
})
app.get('/htState', function (req, res) {
  console.log(req.query)
  const token = "a700123";
  const event=req.query.event;
  const url = "http://192.168.0.100/?token="+token+"&event="+event
  request(url, function (error, response, body) {
    res.send(body)
  });
})





app.listen(3000, () => {
  console.log("listenIng in 3000");
})